package logic

import (
	"ball/models/mysql"
	"context"
	"fmt"

	"ball/ballrpc/ballrpc"
	"ball/ballrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowLogic {
	return &ShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 帖子详情
func (l *ShowLogic) Show(in *ballrpc.ShowRequest) (*ballrpc.ShowResponse, error) {
	// todo: add your logic here and delete this line
	var post mysql.Post
	mysql.DB.Debug().Where("id=?", in.Id).Find(&post)
	if post.ID == 0 {
		return nil, fmt.Errorf("帖子不存在")
	}
	return &ballrpc.ShowResponse{
		Title: post.Title,
		Desc:  post.Desc,
	}, nil
}
